<%--
  ** Copyright(c) 2005 BroadVision, Inc. All rights reserved.
  **
  ** This software is copyrighted.  Under the copyright laws, this software
  ** may not be copied, in whole or in part, without prior written consent
  ** of BroadVision, Inc. or its assignees. This software is provided under
  ** the terms of a license between BroadVision and the recipient, and its
  ** use is subject to the terms of that license.
  **
  ** This software may be protected by one or more U.S. and International
  ** patents. Certain applications of BroadVision One-To-One software are
  ** covered by U.S. patent 5,710,887.
  **
  ** TRADEMARKS: BroadVision and the BroadVision logo are registered
  ** trademarks, and BroadVision One-To-One is a trademark of BroadVision,
  ** Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,
  ** MD5, and RC2 are trademarks of RSA Data Security, Inc. All other
  ** trademarks, service marks, and trade names belong to their respective
  ** owners. BroadVision, Inc. disclaims any proprietary interest in the
  ** marks and names of others.
  --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<%@ page import="java.util.HashMap" %>

<c:set var="view" value="${reportTaskListView}"/>
<c:choose>
  <c:when test="${empty flowIndex || flowIndex < 0}">
    <c:set var="taskListShell" value="processEdit"/>
  </c:when>
  <c:otherwise>
    <c:set var="taskListShell" value="pageflowEdit"/>
  </c:otherwise>
</c:choose>

<%
final String ctxPath = request.getContextPath();

final String trClassList[] = { "listEven", "listOdd" };
pageContext.setAttribute("listFlipFlop", trClassList);
%>

<script language="Javascript">
  function deleteTask(url)
  {
    var msg = '<bean-el:message key="bp.report.task.${taskType}.confirm.delete" bundle="bp.messages"/>';

    if (!confirm(msg))
      return false;

    location.replace(url);
    return true;
  }
</script>

<c:set var="editImg">
  <img src="<%=ctxPath%>/bp/images/action/icon_edit.gif"
       width="15" height="15" border="0" class="actionIcon"
       alt='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>'
       title='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>'
  >
</c:set>      
<c:set var="deleteImg">
  <img src="<%=ctxPath%>/bp/images/action/icon_delete.gif"
       width="15" height="15" border="0" class="actionIcon"
       alt='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>'
       title='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>'
  >
</c:set>

<tr>
  <td valign="top" colspan="100%">
    <div class="pageSubtitle">
      <span class="left">
        <bean-el:message
          key="bp.report.${taskListShell}.${taskType}.subtitle"
          bundle="bp.messages"
        />
      </span>
      <span class="right">&nbsp;</span>
    </div>

    <table class="dataTable" border="0" cellspacing="1" cellpadding="2"
           summary="task table" width="100%">
      <tr class="listHeader">
        <th id="task:Name" align="left">
          <bean-el:message
            key="bp.report.${taskListShell}.${taskType}.header.name"
            bundle="bp.messages"
          />
        </th>
        <c:if test="${!empty view.aliasList}">
          <th id="task:Alias" align="left">
            <bean-el:message
              key="bp.report.${taskListShell}.${taskType}.header.alias"
              bundle="bp.messages"
            />
          </th>
        </c:if>
        <th id="task:Documentation" align="left">
          <bean-el:message
            key="bp.report.${taskListShell}.${taskType}.header.documentation"
            bundle="bp.messages"
          />
        </th>
        <th id="task:Actions" align="left">
          <bean-el:message key="header.actions" bundle="bp.messages"
          />
        </th>
      </tr>

      <c:choose>
        <c:when test="${empty view.nameList}">
          <tr class="listEven">
            <td align="center" colspan="4">
              <bean-el:message
                key="bp.report.${taskListShell}.${taskType}.none"
                bundle="bp.messages"
              />
            </td>
          </tr>
        </c:when>
        <c:otherwise>
          <c:forEach var="name" items="${view.nameList}" varStatus="index">
            <c:choose>
              <c:when test="${taskType=='pageflow'}">
                <c:set var="taskFlowIndex" value="${index.count-1}"/>
              </c:when>
              <c:otherwise>
                <c:set var="taskFlowIndex" value="${flowIndex}"/>
              </c:otherwise>
            </c:choose>
            <c:url var="editUrl" value="/bp/reportTaskEdit/${taskType}.do">
              <c:param name="taskIndex" value="${index.count-1}"/>
              <c:param name="procIndex" value="${procIndex}"/>
              <c:param name="flowIndex" value="${taskFlowIndex}"/>
            </c:url>
            <c:url var="delUrl"
                   value="/bp/reportTaskDelete/${taskListShell}.do">
              <c:param name="taskIndex" value="${index.count-1}"/>
              <c:param name="procIndex" value="${procIndex}"/>
              <c:param name="flowIndex" value="${taskFlowIndex}"/>
              <c:param name="taskType" value="${taskType}"/>
            </c:url>
            <tr class="<c:out value="${listFlipFlop[(index.count-1)%2]}"/>">
              <td headers="task:Name">
                <c:if test="${empty name}">
                  <c:set var="name">
                    <bean-el:message
                      key="bp.report.task.nameNotAvailable" bundle="bp.messages"
                    />
                  </c:set>
                </c:if>
                <a href="<c:out value="${editUrl}" escapeXml="false"/>">
                  <c:out value="${name}"/>
                </a>
              </td>
              <c:if test="${!empty view.aliasList}">
                <td headers="task:Alias">
                  <c:out value="${view.aliasList[index.count-1]}"/>
                </td>
              </c:if>
              <td headers="task:Documentation">
                <c:out value="${view.descList[index.count-1]}"/>
              </td>
              <td headers="task:Actions" align="left" nowrap>
                <a href="<c:out value="${editUrl}" escapeXml="false"/>">
                  <c:out value="${editImg}" escapeXml="false"/>
                </a>
                <a href="#" onclick="deleteTask('<c:out value="${delUrl}"/>')">
                  <c:out value="${deleteImg}" escapeXml="false"/>
                </a>
              </td>
            </tr>
          </c:forEach>
        </c:otherwise>
      </c:choose>

      <%
      final HashMap map = (HashMap)pageContext.getAttribute("view");
      final Object taskList[] = (Object[])map.get("availableTasks");
      pageContext.setAttribute(
                      "availableTasksCount", new Integer(taskList.length));
      %>
      <c:if test="${availableTasksCount > 0}">
        <c:choose>
          <c:when test="${taskListShell == 'processEdit'}">
            <c:set var="taskValueProperty" value="taskName"/>
            <c:set var="taskLabelProperty" value="friendlyName"/>
          </c:when>
          <c:when test="${taskListShell == 'pageflowEdit'}">
            <c:set var="taskValueProperty" value="name"/>
            <c:set var="taskLabelProperty" value="name"/>
          </c:when>
        </c:choose>
        <c:set var="taskList" value="${view.availableTasks}"/>
        <html-el:form action="/bp/reportTaskAdd/${taskListShell}.do">
          <html-el:hidden
            name="reportTaskForm" property="procIndex" value="${procIndex}"
          />
          <html-el:hidden
            name="reportTaskForm" property="flowIndex" value="${flowIndex}"
          />
          <html-el:hidden
            name="reportTaskForm" property="taskType" value="${taskType}"
          />
          <tr>
            <td headers="task:Name" align="left" colspan="2" nowrap>
              <html-el:select property="taskAlias">
                <html-el:options
                  collection="taskList"
                  property="${taskValueProperty}"
                  labelProperty="${taskLabelProperty}"
                />
              </html-el:select>
              &nbsp;
              <html-el:submit styleClass="inputButton" property="submitBtn">
                <bean-el:message key="button.add" bundle="bp.messages"/>
              </html-el:submit>
            </td>
          </tr>
        </html-el:form>
      </c:if>
      <c:if test="${availableTasksCount <= 0}">
        <tr>
          <td colspan="4" align="left">
            <bean-el:message
              key="bp.report.${taskListShell}.${taskType}.noMoreAvailable"
              bundle="bp.messages"
            />
          </td>
        </tr>
      </c:if>

    </table>
  </td>
</tr>

<!-- =============================================================
  ** vim: set ts=2 expandtab syntax=jsp:
  -->
